package com.example.administrator.myapplication.service;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;

import com.example.administrator.myapplication.MyBaseActivity;

/**
 * Created by Administrator on 2017/8/3 0003.
 * 设计为单例模式
 */

public class InitSettings extends GloabSettings{
    private static final String TAG = "InitSettings";
    private Context mContext;
    private SharedPreferences sharedPreferences;
    private static InitSettings initSettings;
    private boolean transverse_screen_state; //是否开启横屏模式，true为开启
    private InitSettings(Context context){
        this.mContext = context;
         sharedPreferences = mContext.getSharedPreferences(SETTINGS_GLOAB, 0);
    }

    public static synchronized InitSettings getInstance(Context context) {

            initSettings = new InitSettings(context);

        return  initSettings;
    }

    /**
     * 初始化所有Activity的屏幕方向
     */
    @Override
    public void init_transverse_screen_state(){
                getTransverse_screen_state();
                if(transverse_screen_state){
                    Log.i(TAG, "初始化屏幕方向为横向！");
                    ((MyBaseActivity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }else {
                    Log.i(TAG, "初始化屏幕方向为纵向！");
                    ((MyBaseActivity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        }




    }

    @Override
    public boolean getTransverse_screen_state() {
        //默认竖屏
        transverse_screen_state =  sharedPreferences.getBoolean(Transverse_screen_state_NAME, false);
        return transverse_screen_state;
    }

    @Override
    public synchronized void setTransverse_screen_state() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(InitSettings.Transverse_screen_state_NAME, transverse_screen_state);
        editor.commit();
    }

    @Override
    public void setTransverse_screen_state(boolean transverse_screen_state) {
        this.transverse_screen_state = transverse_screen_state;
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(InitSettings.Transverse_screen_state_NAME, transverse_screen_state);
        editor.commit();


    }
}
